package com.billy.ohos.swipe.demo.consumer;

import com.billy.ohos.swipe.SmartSwipe;
import com.billy.ohos.swipe.SmartSwipeWrapper;
import com.billy.ohos.swipe.SwipeConsumer;
import com.billy.ohos.swipe.consumer.BezierBackConsumer;
import com.billy.ohos.swipe.demo.BaseAbility;
import com.billy.ohos.swipe.demo.ResourceTable;
import com.billy.ohos.swipe.listener.SimpleSwipeListener;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;

/**
 * demo:
 *
 * @author billy.qi
 */
public class SwipeBackBezierConsumerAbility extends BaseAbility {

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        ComponentContainer parse = (ComponentContainer) LayoutScatter.getInstance(this)
                .parse(ResourceTable.Layout_ability_with_description, null, false);
        super.setUIContent(parse);
        Text textView = (Text) findComponentById(ResourceTable.Id_description);
        textView.setText(ResourceTable.String_demo_description_SwipeBackBezierConsumer);

        SmartSwipe.wrap(parse)
                .removeAllConsumers()
                .addConsumer(new BezierBackConsumer())
                .enableAllDirections()
                .addListener(new SimpleSwipeListener() {
                    @Override
                    public void onSwipeOpened(SmartSwipeWrapper wrapper, SwipeConsumer consumer, int direction) {
                        terminateAbility();
                    }
                });
    }

    @Override
    public int getTitleResId() {
        return ResourceTable.String_demo_ui_BezierBackConsumer;
    }
}
